package com.hzqy.web.ac;

import java.text.SimpleDateFormat;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.commons.utils.DateUtil;
import com.hzqy.service.cleaner.CleanerServiceBean;
import com.hzqy.web.vo.CmContentVo;
import com.hzqy.web.vo.PmsOrgVo;

@Controller
@RequestMapping("/industry/Cleaner")
public class CleanerAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
    private CleanerServiceBean cleanerServiceBean;
	
	@RequestMapping("/selectCleanerTime")
	@ResponseBody
	public List<Object> selectCleanerTime(HttpSession session,CmContentVo cmContentVo){
		List<Object> obs = cleanerServiceBean.selectCleanerTime(cmContentVo);
		return obs;
	}
	
	@RequestMapping("/deleteCleanerPlan")
	@ResponseBody
	public int deleteCleanerPlan(HttpSession session,CmContentVo cmContentVo){
		int flag = cleanerServiceBean.deleteCleanerPlan(cmContentVo);
		return flag;
	}
	
	@RequestMapping("/updateCleanerTime")
	@ResponseBody
	public int updateCleanerTime(HttpSession session,CmContentVo cmContentVo,PmsOrgVo pmsOrgVo){
		int flag = 0;
		PmsOrgVo pms = new PmsOrgVo();
		CmContentVo contentVo =  cleanerServiceBean.selectContentById(cmContentVo);
		contentVo.setF_cc_obligate2(cmContentVo.getF_cc_obligate2());
		int conut =  cleanerServiceBean.selectCleanerCount(contentVo);
		pms =  cleanerServiceBean.selectPmsCleanerResidue(pmsOrgVo);
		if(pms.getF_po_platform_type()>conut){
			contentVo.setF_cc_viewindex(contentVo.getF_cc_viewindex()+1);
			flag = cleanerServiceBean.updateCleanerTime(contentVo);
		}
		return flag;
	}
	
	
	@RequestMapping("/selectPmsCleanerResidue")
	@ResponseBody
	public PmsOrgVo selectCleanerConunt(HttpSession session,PmsOrgVo pmsOrgVo,CmContentVo contentVo){
		PmsOrgVo pms = new PmsOrgVo();
		CmContentVo cmContentVo =  cleanerServiceBean.selectContentById(contentVo);
		int conut =  cleanerServiceBean.selectCleanerCount(cmContentVo);
		pms =  cleanerServiceBean.selectPmsCleanerResidue(pmsOrgVo);
		if(pms.getF_po_platform_type() > conut){
			pms.setF_po_platform_type(pms.getF_po_platform_type()-conut);
		}else{
			pms.setF_po_platform_type(0);
		}
		return pms;
		
	}
	
}
